//
//  ELCOverlayImageView.m
//  ELCImagePickerDemo
//
//  Created by Seamus on 14-7-11.
//  Copyright (c) 2014年 ELC Technologies. All rights reserved.
//

#import "ELCOverlayImageView.h"
#import "ELCConsole.h"
@implementation ELCOverlayImageView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setIndex:(int)_index
{
    self.labIndex.text = [NSString stringWithFormat:@"%d",_index];
}

- (void)dealloc
{
    self.labIndex = nil;
}

- (id)init
{
    self = [super init];
    if (self) {
//        UIImageView *img = [[UIImageView alloc] initWithImage:image];
//        [self addSubview:img];
        
        if ([[ELCConsole mainConsole] onOrder]) {
            self.labIndex = [UILabel new];
            self.labIndex.backgroundColor = [UIColor colorWithRGB:0xff430d];
            self.labIndex.clipsToBounds = YES;
            self.labIndex.textAlignment = NSTextAlignmentCenter;
            self.labIndex.textColor = [UIColor whiteColor];
            self.labIndex.layer.cornerRadius = 9.5;
            self.labIndex.layer.shouldRasterize = YES;
            self.labIndex.userInteractionEnabled = YES;
            [self.labIndex addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelSelect)]];
            //        self.labIndex.layer.borderWidth = 1;
            //        self.labIndex.layer.borderColor = [UIColor greenColor].CGColor;
            self.labIndex.font = [UIFont boldSystemFontOfSize:13];
            [self addSubview:self.labIndex];
            [self.labIndex mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(19 , 19));
                make.right.mas_equalTo(self.mas_right).offset(-2);
                make.top.mas_equalTo(self.mas_top).offset(2);
            }];
            
            
            self.selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [self.selectBtn addTarget:self action:@selector(buttonPressed:forEvent:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.selectBtn];
            [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(21, 21));
                make.right.mas_equalTo(self.mas_right);
                make.top.mas_equalTo(self.mas_top);
            }];
            [self.selectBtn setImage:[UIImage imageNamed:@"image_picker_mark_white"] forState:UIControlStateNormal];
        }
    }
    return self;
}

- (void)buttonPressed:(id)sender forEvent:(UIEvent*)event{
    if ([_delegate respondsToSelector:@selector(selectWithOverlayView:)]){
        [_delegate selectWithOverlayView:self];
    }
}

- (void)labelSelect{
    if ([_delegate respondsToSelector:@selector(deSelectWithOverlayView:)]){
        [_delegate deSelectWithOverlayView:self];
    }
}


@end
